using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Turquoise.EntityGenerator.Models.Mapping
{
    public class FileMap : EntityTypeConfiguration<File>
    {
        public FileMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.FileName)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.FileType)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.FilePath)
                .HasMaxLength(255);

            // Table & Column Mappings
            this.ToTable("File");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.FileGuid).HasColumnName("FileGuid");
            this.Property(t => t.FileName).HasColumnName("FileName");
            this.Property(t => t.FileLength).HasColumnName("FileLength");
            this.Property(t => t.FileType).HasColumnName("FileType");
            this.Property(t => t.FileBuffer).HasColumnName("FileBuffer");
            this.Property(t => t.FilePath).HasColumnName("FilePath");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");
            this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
            this.Property(t => t.UpdateDate).HasColumnName("UpdateDate");
            this.Property(t => t.UpdatedBy).HasColumnName("UpdatedBy");
            this.Property(t => t.IsApproved).HasColumnName("IsApproved");

            // Relationships
            this.HasRequired(t => t.User)
                .WithMany(t => t.Files)
                .HasForeignKey(d => d.CreatedBy);
            this.HasRequired(t => t.User1)
                .WithMany(t => t.Files1)
                .HasForeignKey(d => d.UpdatedBy);

        }
    }
}
